package com.crm.CLdriving.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.IdReqDto;
import com.crm.CLdriving.dto.req.SubInputReqDto;
import com.crm.CLdriving.dto.req.SubInsertReqDto;
import com.crm.CLdriving.dto.req.SubOneUpdateByIdReqDto;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.SubjectOnePO;
import com.crm.CLdriving.service.SubOneService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

@Api(tags="科目一信息管理")
@Controller
@Log4j2
@RequestMapping("subone")
public class SubOneController {
	
	@Autowired
	private SubOneService subOneService;
	
	@PostMapping("selectall")
	@ResponseBody
	@ApiOperation("科目一所有学员信息查询接口")
	public BaseResponse<List<SubjectOnePO>> selectAll(){
		return subOneService.selectall();
	}
	
	@PostMapping("insert")
	@ResponseBody
	@ApiOperation("科目一信息录入接口")
	public BaseResponse<?> Insert(@RequestBody @Valid SubInsertReqDto subInsertReqDto){
		log.info("科目请求参数为     ："+JSON.toJSONString(subInsertReqDto));
		return subOneService.insert(subInsertReqDto);	
	}
	
	
	@PostMapping("selectById")
	@ResponseBody
	@ApiOperation("id查询科目一信息接口")
	public BaseResponse<SubjectOnePO> SelectById(@RequestBody IdReqDto idReqDto){
		log.info("id::::::::::::"+JSON.toJSONString(idReqDto));
		return subOneService.selectById(idReqDto);
	}
	
	@PostMapping("deleteById")
	@ResponseBody
	@ApiOperation("删除科目一信息接口")
	public BaseResponse<?> DeleteById(@RequestBody IdReqDto idReqDto){
		return subOneService.delete(idReqDto);	
	}
	
	@PostMapping("updateById")
	@ResponseBody
	@ApiOperation("更新科目一信息接口")
	public BaseResponse<?> UpdateById(@RequestBody @Valid SubOneUpdateByIdReqDto subOneUpdateByIdReqDto){
		log.info("更新科目一请求参数："+JSON.toJSONString(subOneUpdateByIdReqDto));
		return subOneService.updateById(subOneUpdateByIdReqDto);
	}

	@PostMapping("selectInput")
	@ResponseBody
	@ApiOperation("筛选框查询信息接口")
	public BaseResponse<List<SubjectOnePO>> SelectInput(@Valid @RequestBody SubInputReqDto subInputReqDto){
		log.info("筛选框请求参数："+JSON.toJSONString(subInputReqDto));
		if ((subInputReqDto.getIdentity()==null || subInputReqDto.getIdentity()=="") &&
				(subInputReqDto.getName()==null || subInputReqDto.getName()=="")) {
			return BaseResponse.message(ResponseEnum.MYSXTJ);
		}
		return subOneService.selectInput(subInputReqDto);
	}
}
